﻿using System;
using System.Collections.Generic;

using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using HZ.DrugTrade.IBLL;
using HZ.DrugTrade.BLLFactory;
using HZ.DrugTrade.Model;
using System.Data;
using HZ.DrugTrade.Model.Enum;

namespace HZ.DrugTrade.Web.Admin.RelationQuery
{
    public partial class CompanyDelLogDetail :BasePage
    {

        public CompanyDelLogDetail()
        {
            this.ModuleNo = Module.查看不良记录.ToString();
        }


        IBLL_AreaDistributionDelLog ih = Factory.BLL_AreaDistributionDelLog();
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                SetBind();
            }
        }

        /// <summary>
        /// 绑定符合条件的采购明细
        /// </summary>
        private void SetBind()
        {
            int totalCount;
            IList<Model.View.AreaDistributionDelLog> purchaseOrderDetailList = ih.GetAreaDistributionDelLogByProcureCatalogID(GetQuery(), AspNetPager1.CurrentPageIndex, AspNetPager1.PageSize, out totalCount);
            AspNetPager1.RecordCount = totalCount;
            GvRelaion.PageSize = AspNetPager1.PageSize;
            GvRelaion.DataSource = purchaseOrderDetailList;
            GvRelaion.DataBind();
        }
        public Model.Query.AreaDistributionDelLog GetQuery()
        {

            Model.Query.AreaDistributionDelLog where = new HZ.DrugTrade.Model.Query.AreaDistributionDelLog();
            if (string.IsNullOrEmpty(Request["CompanyID"]))
                PageError("系统参数错误", this.ReturnUrl);

            where.Append = string.Format(" CompanyID_PS='{0}' Or CompanyID_TB='{0}' ",Request["CompanyID"]);

            string strAreaID = GetAreaID();
            if (string.IsNullOrEmpty(strAreaID) == false && strAreaID.EndsWith("0000") == false)
            {
                where.AreaID = strAreaID;//地区ID
            }

            //  where.AreaID = Request["AreaID"];
            where.GoodsID = txtGoodsID.Text.Trim();//产品编号
            where.GoodsName = txtGoodsName.Text.Trim();//产品名称
            where.Material = txtMaterial.Text.Trim();//材质
            where.Outlookc = txtOutlookc.Text.Trim();
           
            where.SortFields = " AreaID ";
            return where;
        }

        /// <summary>
        /// 查询
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void btnQuery_Click(object sender, EventArgs e)
        {
            AspNetPager1.CurrentPageIndex = 1;

            SetBind();
        }

        /// <summary>
        /// 翻页
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void AspNetPager1_OnPageChanged(object sender, EventArgs e)
        {
            SetBind();
        }


        /// <summary>
        /// 导出2009-11-25
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void btnExport_Click(object sender, EventArgs e)
        {

            int totalCount = 0;
            IList<Model.View.AreaDistributionDelLog> purchaseOrderDetailList = ih.GetAreaDistributionDelLogByProcureCatalogID(GetQuery(), 1, 0, out totalCount);
            System.Data.DataTable tb = HZ.Data.ModelConvert.GetDataTableFromModel(purchaseOrderDetailList);
            HZ.Excel.ExcelHelper.ExportDataForWeb(tb, GvRelaion);

        }

        /// <summary>
        /// 获取地区ID
        /// </summary>
        /// <returns></returns>
        private string GetAreaID()
        {
            string areaId = "";

            //首次进入使用系统部署所在区域ID
            Model.Area aArea = CurrentAccount.GetCurrentDeployArea();  //获取当前实施地区的地区
            areaId = aArea.AreaID;

            //优先获取城市，再次省份
            if (new Common.ConvertHelper(Request.Form["ctl00$ContentPlaceHolder1$ddlCity"]).String != Constants.ALL_ITEM_VALUE)
            {
                areaId = Request.Form["ctl00$ContentPlaceHolder1$ddlCity"];
            }
            else if (new Common.ConvertHelper(Request.Form["ctl00$ContentPlaceHolder1$ddlProvice"]).String != Constants.ALL_ITEM_VALUE)
            {
                areaId = Request.Form["ctl00$ContentPlaceHolder1$ddlProvice"];
            }

            return areaId;
        }
        /// <summary>
        /// 获取默认选中的地区编号串
        /// </summary>
        /// <returns></returns>
        protected string GetDefaultAreaString()
        {
            //默认城市 江苏省 320000
            string defaultCity = "";
            string defaultProvince = "";

            Model.Area aArea = CurrentAccount.GetCurrentDeployArea();  //获取当前实施地区的地区

            defaultProvince = aArea.AreaID;

            string strArea = "";
            //显示默认地区
            strArea += "," + "\"" + defaultProvince + "\"";
            this.ddlProvice.Enabled = false;
            if (!string.IsNullOrEmpty(defaultCity))
            {
                strArea += "," + "\"" + defaultCity + "\"";
                this.ddlCity.Enabled = false;
            }
            else if (!string.IsNullOrEmpty(Request.Form["ctl00$ContentPlaceHolder1$ddlCity"]))
            {
                strArea += "," + "\"" + Request.Form["ctl00$ContentPlaceHolder1$ddlCity"] + "\"";
            }

            if (!string.IsNullOrEmpty(Request.Form["ctl00$ContentPlaceHolder1$ddlCountry"]))
            {
                strArea += "," + "\"" + Request.Form["ctl00$ContentPlaceHolder1$ddlCountry"] + "\"";
            }

            return strArea;
        }
    }
}
